home *** CD-ROM | disk | FTP | other *** search
- Path: news.nyu.edu!schonberg!dewar
- From: dewar@cs.nyu.edu (Robert Dewar)
- Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.edu
- Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada)
- Date: 9 Apr 1996 07:27:51 -0400
- Organization: Courant Institute of Mathematical Sciences
- Message-ID: <dewar.829048603@schonberg>
- References: <JSA.96Feb16135027@organon.com> <dewar.828936837@schonberg> <828964950snz@genesis.demon.co.uk> <dewar.828987544@schonberg> <4kbuebINNrho@keats.ugrad.cs.ubc.ca>
- NNTP-Posting-Host: schonberg.cs.nyu.edu
- X-Newsreader: NN version 6.5.0 (NOV)
-
- "This is so deeply entrenched in the realm of common sense that it isn't even
- worth mentioning in a standard document! Nevertheless, I have access to the
- POSIX.1 standard and will look into this."
-
- This seems complete nonsense. There are two possible semantics that ould
- be defined for read (buffer must be at least size of the read argument,
- or buffer must be at least size of data read). Both are easy to specify,
- both are easy to implement. You cannot rely on common sense (especially
- dubious reasoning about kernels and what not that are totally irrelevant
- to the semantic specification). The idea that specs are derived from
- implementations (either by looking at the implementation, or reasoning
- about it with "common sense" or otherwise) is completely unacceptable!
-
- (though unfortunately very common, especially when people are writing in
- a language that does not make a big deal about separating spec and
- implementation details).
-
- My only at-hand sources are K&R, which has nothing whatever to say on
- the subject, the Zortech C++ reference, which also has nothing to say,
- (both describe read, but say nothing about the buffer length), and
- the Microsoft Runtime Reference which talks about "attempting to
- read n bytes", but is otherwise unclear.
-
- We are after all dealing with a language interface where in practice the
- proper check (whichever it is) cannot be made, because the called routine
- does not know the length of the buffer passed. I think a natural default
- assumption, in the absence of any statement to the contrary, is that the
- bytes are blindly read into the buffer, and disaster strikes if the number
- of bytes read is greater than the buffer length, but otherwise all is well.
- Unless there is a VERY clear statement of semantics to the contrary, I
- don't see how anyone can call code that makes this assumption obviously
- broken.
-
- This is of course a rather trivial detail but is instructive with regard
- to the importance of writing precise specs. Kazimir's claim that the spec
- obviously requires that the buffer length match the requested, rather
- than actual length, based on some dubious reasoning about likely
- implementation models is just the sort of thing that needs to be
- eliminated from programming practices. Specs need to be made precise,
- so that a caller knows EXACTLY what the requirements are without having
- to guess, or, worse still, examine the actual implementation code.
-
-